<template>
  <div class="section-wrap" style="height:100%;margin-top: 40px;">
      <!-- 头部 -->
      <div class="headerBox">
        <div class="header">
          <x-icon type="ios-arrow-left" size="" class="icon-white" @click="goBack"></x-icon>
          问题整改
        </div>
      </div>
      <vue-better-scroll
        class="wrapper"
        ref="scrollqq"
        :scrollbar="scrollbarObj"
        :pullDownRefresh="pullDownRefreshObj"
        :pullUpLoad="pullUpLoadObj"
        :startY='parseInt(startY)'
        @pullingUp="onPullingUp"
      >
      <div class="form-section">
        <div class="zginfoDiv2">
          <ul>
            <li v-for="(value, key) in hiddenType" :key="key" :class="falg==key?'active':''" @click="tabChange(key)">{{value}}</li>
          </ul>
        </div>
        <!-- 待整改问题 -->
        <div class="one" v-if="falg === 0">
          <div class="info_div2">
            <div class="form-item">
              <div><span style="float: right">问题总数：{{totalCount}}</span></div>
            </div>
          </div>
          <div class="project_div">
            <ul class="project_list" v-if="falg === 0">
              <li @click="goAddHiddenZg(zgItem.id)" v-for="zgItem in accpentlist" :key="zgItem.id">
                <div class="lf">
                  <div>
                    <span style="font-size: 15px">{{zgItem.hiddenDangerNum}}</span><br>
                    <span class="content" style="display: box;">{{zgItem.hiddenDangeDescription}}</span>
                  </div>
                  <div>
                    <span class="status" :class="{'big': zgItem.hiddenDangerLevel.includes('重大')}">【{{zgItem.hiddenDangerLevel}}】</span>
                    <span style="font-size: 12px;color: #ffb400" v-if="zgItem.status=='0'">待提交</span>
                    <span style="font-size: 12px;color: #ffb400" v-if="zgItem.status=='1'">待整改</span>
                    <span style="font-size: 12px;color: #ffb400" v-if="zgItem.status=='2'">待验收</span>
                    <span style="font-size: 12px;color: #999999" v-if="zgItem.status=='3'">已关闭</span>
                  </div>
                </div>
                <div class="rf">
                  <img v-if="zgItem.projectImgList && zgItem.projectImgList.length!=0" :src="zgItem.projectImgList[0].url" style="width: 130px;height: 100px" alt="">
                  <img v-if="!zgItem.projectImgList || zgItem.projectImgList.length==0" src="../../../static/images/hidden/pic.jpg" style="width: 130px;height: 100px" alt="">
                </div>
              </li>
            </ul>
          </div>
        </div>
        <!-- 我的 -->
        <div class="two" v-if="falg === 1">
          <div class="info_div2">
            <div class="form-item">
              <div><span style="float: right">问题总数：{{personalTotalCount}}</span></div>
            </div>
          </div>
          <div class="project_div">
            <ul class="project_list">
              <li @click="goAddHiddenZg(zgPerItem.id)"  v-for="zgPerItem in personalAccpentlist" :key="zgPerItem.id">
                <div class="lf">
                  <div>
                    <span style="font-size: 15px">{{zgPerItem.hiddenDangerNum}}</span><br>
                    <span class="content" style="display: box;">{{zgPerItem.hiddenDangeDescription}}</span>
                  </div>
                  <div>
                    <span class="status" :class="{'big': zgPerItem.hiddenDangerLevel.includes('重大')}">【{{zgPerItem.hiddenDangerLevel}}】</span>
                    <span style="font-size: 12px;color: #ffb400" v-if="zgPerItem.status=='1'">待整改</span>
                    <span style="font-size: 12px;color: #ffb400" v-if="zgPerItem.status=='2'">待验收</span>
                    <span style="font-size: 12px;color: #999999" v-if="zgPerItem.status=='3'">已关闭</span>
                  </div>
                </div>
                <div class="rf">
                  <img v-if="zgPerItem.projectImgList && zgPerItem.projectImgList.length!=0" :src="zgPerItem.projectImgList[0].url" style="width: 130px;height: 100px" alt="">
                  <img v-if="!zgPerItem.projectImgList || zgPerItem.projectImgList.length==0" src="../../../static/images/hidden/pic.jpg" style="width: 130px;height: 100px" alt="">
                </div>
              </li>
            </ul>
          </div>
        </div>
      </div>
    </vue-better-scroll>
  </div>

</template>
<script>
  import axios from 'axios';
  import selectDepart from "@commonComponents/selectDepart/selectDepart";
  import VueBetterScroll from "vue2-better-scroll"
  import {
    XHeader,
    Tabbar,
    TabbarItem,
    Group,
    Cell,
    TransferDom,
    Popup
  } from "vux";

  export default {
    directives: {
      TransferDom
    },
    data() {
      return {
        isPersonal: false, // 是否为个人问题整改信息，默认为false查询全部信息
        hiddenType:["待整改问题","我的"],
        falg: 0,
        isjifen: [],
        accopt1: [['已整改', '待整改']],
        /*下拉刷新*/
        resultlist: [],
        scrollbarObj: {fade: true},
        pullDownRefreshObj: false,
        pullUpLoadObj: {
          threshold: 0,
          txt: {
            more: "加载更多",
            noMore: "没有更多数据了"
          }
        },
        startY: 0,
        scrollToX: 0,
        scrollToY: 0,
        scrollToTime: 700,
        url: "/api/services/app/Assessment/GetPageList",
        isDisabled: true, // 是否禁止输入
        totalCount: 0, // 问题整改总数
        personalTotalCount: 0, //个人问题整改总数
        accpentlist: [], // 页面当前显示待整改条目（全）
        personalAccpentlist: [], // 页面当前显示待整改条目（个人）
        classValue: false,
        data: [],
        // 问题台账列表查询
        params: {
          startDate: "",
          endDate: "",
          status: "1",
          htype: "",
          level: "",
          onlyzg: "1",
          onlyys: "",
          myDepart: true,
          describe: "",
          bcheckDeptName: "",
          skipCount: 0,
          maxResultCount: 10
        },
        // 我的问题台账查询，必穿字段zgZrrId
        personalParams: {
          startDate: "",
          endDate: "",
          status: "1",
          htype: "",
          level: "",
          onlyzg: "1",
          onlyys: "",
          myDepart: true,
          describe: "",
          bcheckDeptName: "",
          skipCount: 0,
          maxResultCount: 10
        },
        startDate: '',
        endDate: '',
        selectDepartType: 0
      };
    },
    components: {
      selectDepart,
      Popup,
      VueBetterScroll
    },
    created() {
      this.getData();
    },
    mounted(){
      // axios({
      //   url: 'http://localhost/api/services/app/HiddenDangerInfo/GetPageList',
      //   method: 'POST',
      //   data: JSON.stringify(this.params)
      // });
        this.$axiosAjax.getHiddenPageList_DB(this.personalParams).then(res => {
          if (res.data.success == true) {
            this.personalTotalCount = res.data.result.totalCount;
            let relistPersonal = res.data.result.items;
            this.personalAccpentlist = this.personalAccpentlist.concat(relistPersonal);
            let personalTotalCount = res.data.result.totalCount;
            let resultCountPersonal = this.personalAccpentlist.length;
            if (parseInt(resultCountPersonal) < parseInt(personalTotalCount)) {
              this.$refs['scrollqq'].forceUpdate(true);
            } else {
              this.$refs['scrollqq'].forceUpdate(false);
            }
          }
        }).catch(err => {});
        let that = this;
        this.$bridge.registerHandler("setToken", function(data) {
          //这里data ioS返回的是token值(字符串)
          that.$store.state.Authorization = "Bearer " + data;
          that.getData();
        });

        this.connectWebViewJavascriptBridge(function(bridge) {
            bridge.init(function(message, responseCallback) {});

            bridge.registerHandler("setToken", function(data) {
              //这里data android返回的是token值(字符串)
              that.$store.state.Authorization = "Bearer " + data;
              that.getData();
            });
        });
    },
    methods: {
      connectWebViewJavascriptBridge(callback) {
          if (window.WebViewJavascriptBridge) {
              callback(WebViewJavascriptBridge);
          } else {
              document.addEventListener(
              "WebViewJavascriptBridgeReady",
              function() {
                  callback(WebViewJavascriptBridge);
              },
              false
              );
          }
      },
      // 顶部tab栏切换
      tabChange(key) {
        this.falg = key;
        // 获取当前的tab信息
        this.isPersonal = this.hiddenType[key] === "我的";
        // 获取我的整改信息
        if (this.isPersonal) {
          if (this.personalAccpentlist.length === 0) {
            this.getData();
          }
        }
      },
      // 跳转判断是否为本人的可整改内容
      goAddHiddenZg (id) {
        this.$axiosAjax.getHiddenInfo({
            hiddenDangerInfoId: id
        }).then(res => {
          if (res.data.success == true) {
            if (Number(res.data.result.isOneself) === 1) {
              this.$router.push({
                path:`/addHiddenZg?id=${id}`
              });
            } else {
              // 非本人只能查看
              this.$router.push({
                path:`/hiddeDetails?id=${id}`
              });
            }
          }
        });
      },
      getData() {
        // 查询开始时间
        if (this.startDate) {
          this.params.startDate = this.startDate + " 00:00:00";
        }
        // 查询结束时间
        if (this.endDate) {
          this.params.endDate = this.endDate + " 00:00:00";
        }
        // 查询待整改列表信息
        let params = null;
        if (this.isPersonal) {
          params = this.personalParams;
        } else {
          params = this.params;
        }
        this.$axiosAjax.getHiddenPageList_DB(params).then(res => {
          if (res.data.success == true) {
            // 区分单位整体更改信息和个人整改信息
            if (this.isPersonal) {
              this.personalTotalCount = res.data.result.totalCount;
              let relistPersonal = res.data.result.items;
              if (this.personalParams.skipCount == 0) {
                this.personalAccpentlist = [];
              }
              this.personalAccpentlist = this.personalAccpentlist.concat(relistPersonal);
              let personalTotalCount = res.data.result.totalCount;
              let resultCountPersonal = this.personalAccpentlist.length;
              if (parseInt(resultCountPersonal) < parseInt(personalTotalCount)) {
                this.$refs['scrollqq'].forceUpdate(true);
              } else {
                this.$refs['scrollqq'].forceUpdate(false);
              }
            } else {
              this.totalCount = res.data.result.totalCount;
              let relist = res.data.result.items;
              if (this.params.skipCount == 0) {
                this.accpentlist = [];
              }
              this.accpentlist = this.accpentlist.concat(relist);
              let totalAllCount = res.data.result.totalCount;
              let resultCount = this.accpentlist.length;
              if (parseInt(resultCount) < parseInt(totalAllCount)) {
                this.$refs['scrollqq'].forceUpdate(true);
              } else {
                this.$refs['scrollqq'].forceUpdate(false);
              }
            }
          }
        }).catch(err => {});
      },
      goBack() {
        // this.$router.go(-1);
        this.$bridge.callHandler({
          type: 'closePage',
          data: {}
        });
      },
      onPullingUp() {
        let limitcount = this.isPersonal ? this.personalAccpentlist.length : this.accpentlist.length;
        if (this.isPersonal) {
          this.personalParams.skipCount = limitcount;
        } else {
          this.params.skipCount = limitcount;
        }
        this.getData();
      }
    }
  };
</script>
<style lang="less" scoped>
  .zginfoDiv2{
    height: 50px;
    ul {
      display: flex;
      justify-content: space-around;
    }
    ul li{
      display: inline-block;
      text-align: center;
      width: 100px;
      line-height: 45px;
      font-size: 15px;
      color: #999999;

    }
    // ul li:first-child{
    //   margin-left: 55px;
    //   margin-right: 80px;
    // }
    .active{
      border-bottom: 3px solid #469b7a;
      padding-bottom: 0px;
      color: #469b7a;
    }
  }
  .search-btn {
    width: 200px;
    line-height: 36px;
    border-radius: 20px;
    margin: 23px auto;
    color: #fff;
    background: #469b7a;
    text-align: center;
    font-size:16px;
    letter-spacing: 4px;
  }

  .content {
    margin-top: 8px;
    font-size: 13px;
    color: #999999;
    width: 180px;
    line-height: 18px;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp:2;
    overflow: hidden;
  }
  .status{
    font-size: 12px;color: #ff7333
  }
  .big{
    color: #ff0000
  }
  .classifyOneName {
    font-size: 12px;
    color: #666;
  }

  .lf {
    text-align: left;
    height: 100%;
    padding: 10px 0;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    .status {
      text-align: left;
      display: inline-block;
      min-width: 80px;
      margin-left: -4px;
    }
  }
  .rf {
    height: 100%;
    padding: 10px;
    img {
      display: block;
      height: 100% !important;
      padding-top: 0 !important;
    }
  }
  .form-item {
    .input_div {
      .vux-x-icon {
        fill: #999;
        float: right;
        margin-top: 18px;
      }

    }
  }

  .project_div {
    .project_list {
      box-sizing: border-box;
      padding-left: 10px;
      li {
        border-bottom: 1px solid #efeff4;
        height: 125px;
        position: relative;
        box-sizing: border-box;
        display: flex;
        justify-content: space-between;
        align-items: center;
        span{
          padding-left: 10px;
          top: 10px;
        }
        h4 {
          width: calc(100% - 50px);
          text-overflow: ellipsis;
          white-space: nowrap;
          overflow: hidden;
          font-size: 16px;
          margin-bottom: 8px;
          font-weight: bold;
        }


        .project_status {
          margin-top: 14px;
          strong {
            font-size: 12px;
          }

          strong.project_status1 {
            color: #ff7333;
          }

          strong.project_status2 {
            color: #469b7a;
          }

        }

        .vux-x-icon {
          fill: #999;
          right: 20px;
          top: 50%;
          margin-top: -11px;
          position: absolute;
        }

      }
    }
  }

  .add_btn {
    position: fixed;
    height: 62px;
    width: 62px;
    right: 30px;
    bottom: 35px;
  }
</style>
